﻿using System;
using System.Collections.Generic;
using System.Linq;
using KTOP.Core;
using KTOP.Core.Netlists.Parsing;
using KTOP.Homeworks.Hw4;
using KTOP.Homeworks.Hw5;
using KTOP.Homeworks.Hw7;

namespace KTOP.Launcher
{
    internal class Program
    {
        private static readonly Dictionary<string, IKtopHomework> TARGETS = new Dictionary<string, IKtopHomework>()
                                                                                {
                                                                                    {"hw4", new Homework4()},
                                                                                    {"hw5", new Homework5()},
                                                                                    {"hw7", new Homework7()}
                                                                                };

        private static void Main(string[] args)
        {
            var options = new Options(TARGETS.Select(kv => kv.Key).ToArray());
            try
            {   
                options.Parse(args);

                var parser = new NetlistParser();
                var netlist = parser.Parse(options.InputFile);

                var hw = TARGETS[options.HwId];
                hw.Do(netlist);
            }
            catch (OptionsException e)
            {
                Console.Error.WriteLine(e.Message);
                Console.Error.WriteLine();

                options.PrintUsage();
            }
        }
    }
}
